package com.glory.brepda.adapter;

import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import androidx.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.glory.brepda.R;
import com.glory.brepda.activity.lanjian.SfcInnerLabelMainActivity;
import com.glory.brepda.entity.EdcSetBinEntity;
import com.glory.brepda.entity.SheetInfoEntity;

import org.apache.commons.lang3.StringUtils;

import java.util.List;

public class CheckG028ListAdapter extends BaseQuickAdapter<String, BaseViewHolder> {

    private PmsEqpHisListAdapter.OnClickListener mListener;

    public CheckG028ListAdapter(@Nullable List<String> data) {
        super(R.layout.adapter_check_g028, data);
    }
    @Override
    protected void convert(BaseViewHolder helper, String item) {
        int n = helper.getAdapterPosition();
        String[] now = item.split("/");
        colorClear(helper);
        if(now.length == 4 || now.length == 3){
            helper.setText(R.id.tvCheckID,now[0]);
            helper.setText(R.id.tvproduct,now[1]);
            helper.setText(R.id.tvnum,now[2]);

            if(now.length == 4){
                helper.setText(R.id.tvcode,now[3]);
                if(!SfcInnerLabelMainActivity.CODE.equals(now[3])){
                    helper.setTextColor(R.id.tvcode, Color.rgb(255,0,0));
                }
            }

            if(!SfcInnerLabelMainActivity.LOT.equals(now[0])){
                helper.setTextColor(R.id.tvCheckID, Color.rgb(255,0,0));
            }
            if(!SfcInnerLabelMainActivity.PRODUCT.contains(now[1])){
                helper.setTextColor(R.id.tvproduct, Color.rgb(255,0,0));
            }

            // 序号重复
            if(n != 0){
                for(int i=0;i<n;i++){
                   if( getItem(i).split("/")[2].equals(now[2])){
                       helper.setTextColor(R.id.tvnum, Color.rgb(0,0,255));
                       break;
                   }
                }
            }
        }

        // 校验数据
//        EditText etValue = helper.getView(R.id.tvCheckID);
//        setEditListener(etValue ,item);

    }

    //重置颜色
    public void colorClear(BaseViewHolder helper){
        helper.setTextColor(R.id.tvCheckID, Color.rgb(0,0,0));
        helper.setTextColor(R.id.tvproduct, Color.rgb(0,0,0));
        helper.setTextColor(R.id.tvcode, Color.rgb(0,0,0));
        helper.setTextColor(R.id.tvnum, Color.rgb(0,0,0));
    }

    public interface OnClickListener{
        void onCheckListener(SheetInfoEntity item);
    }

    public void setOnCheckListener(PmsEqpHisListAdapter.OnClickListener listener){
        this.mListener = listener;
    }

//    private void setEditListener(EditText editText, String item) {
//        if (editText.getTag() instanceof TextWatcher) {
//            editText.removeTextChangedListener((TextWatcher) editText.getTag());
//        }
//
//        TextWatcher watcher = new TextWatcher() {
//            @Override
//            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
//
//            }
//
//            @Override
//            public void onTextChanged(CharSequence s, int start, int before, int count) {
//
//            }
//
//            @Override
//            public void afterTextChanged(Editable s) {
//
//            }
//        };
//
//        editText.addTextChangedListener(watcher);
//        editText.setTag(watcher);
//    }
}
